<table class="table table-striped">
	<thead>
		<tr>
			<th class="text-center">Image</th>
			<th class="text-center">Nom</th>
			<th class="text-center">Actions</th>
		</tr>
	</thead>
	<tbody class="text-center"><?php foreach ($images as $k => $v): ?>
		<tr>
			<td><img src="<?php echo Router::webroot('img/'.$v->file); ?>" alt="<?php echo $v->name; ?>" height="100"></td>
			<td><?php echo $v->name; ?></td>
			<td>
				<a class="btn btn-default btn-sm active" role="button" onclick="return confirm('Voulez-vous vraiment supprimer cette image  ?');" href="<?php echo Router::url('admin/medias/delete/'.$v->id); ?>">Supprimer</a>
			</td>
		</tr><?php endforeach ?>
	</tbody>
</table> 
<div class="page-header">
	<h1>Ajouter une image</h1>
</div>

<form action="<?php echo Router::url('admin/medias/index/'.$post_id); ?>" method="post" enctype="multipart/form-data">
	<div class="form-group">
		<?php echo $this->Form->input('file', 'Image', array('type'=>'file')); ?>
		<?php echo $this->Form->input('name', 'Titre', array('type'=>'text')); ?>
	</div>
	<div class="actions">
		<input type="submit" class="btn btn-primary" value="Envoyer">
	</div>
</form>

<script src="<?php echo Router::webroot('js/jquery.min.js') ;?>"></script>
<script type="text/javascript">
var parentWin = (!window.frameElement && window.dialogArguments) || opener || parent || top;
$(function() {
    $('img').click(function(e){
        e.preventDefault();
        imgSrc = $(this).attr('src');
        imgAlt = $(this).attr('alt');
        divInput = $("input#"+parentWin.inputSrc,parent.document).parent().attr('id');
        divInputSplit = divInput.split("_");
        divTitle = "mce_"+(parseInt(divInputSplit[1],10) +1);
        $("input#"+parentWin.inputSrc,parent.document).val(imgSrc);
        $("input#"+divTitle,parent.document).val(imgAlt);
        $(".mce-close",parent.document).last().trigger("click");
    });

    $('img').hover(function() {
        $(this).css('cursor','pointer');
    });
});
</script>